<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="__ADMIN__/pear/css/pear.css" />
</head>

<body>
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label for="" class="layui-form-label">标题：</label>
                    <div class="layui-input-block">
                        <input type="text" name='title' class="layui-input" required>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="" class="layui-form-label">SEO描述：</label>
                    <div class="layui-input-block">
                        <textarea name="desc" class="layui-textarea" placeholder="输入描述"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label for="" class="layui-form-label">分类：</label>
                        <div class="layui-input-inline">
                            <select name="cid">
                                <option value=""></option>
                                <option value="1" selected>好物推荐</option>
                                <option value="2">分类2</option>
                                <option value="3">分类2</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label for="" class="layui-form-label">作者：</label>
                        <div class="layui-input-inline">
                            <select name="adminid">
                                <option value=""></option>
                                <option value="1" selected>admin</option>
                                <option value="2">分类2</option>
                                <option value="3">分类2</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">

                    <label for="" class="layui-form-label">状态:</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="0" title="草稿">
                        <input type="radio" name="status" value="1" title="待审核">
                        <input type="radio" name="status" value="2" title="发布" checked>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="" class="layui-form-label">文章内容:</label>
                    <div class="layui-input-block">
                        <div id="con"></div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <label for="" class="layui-form-label">缩略图：</label>
                    <div class="layui-input-block">
                        <input type="text" name="imgurl" class="layui-input" placeholder="缩略图网址">
                    </div>
                </div>
            </div>
        </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
            </div>
        </div>
    </form>
    <script src="__ADMIN__/layui/layui.js"></script>
    <script src="__ADMIN__/pear/pear.js"></script>
    <script>
        layui.use(['form', 'jquery', 'layedit', 'uploads', 'tinymce'], function() {
            let form = layui.form;
            let $ = layui.jquery;
            let layedit = layui.layedit
            let tinymce = layui.tinymce
            var con = tinymce.render({
                elem: "#con",
                height: 400
            });
            // edit.getContent()


            form.on('submit(save)', function(data) {
                data.field.content = con.getContent()
                $.ajax({
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function(res) {
                        //判断有没有权限
                        if (res && res.code == 999) {
                            layer.msg(res.msg, {
                                icon: 5,
                                time: 2000,
                            })
                            return false;
                        } else if (res.code == 0) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                                parent.layui.table.reload("dataTable");
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
                return false;
            });
        })
    </script>
</body>

</html>